$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'mark/tinfmark/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
            { label: '标的名称', name: 'markName', index: 'mark_name', width: 80 },
			// { label: '标的期限', name: 'markTerm', index: 'mark_term', width: 80 },
			//
			{ label: '标的类型', name: 'markType', index: 'mark_type', width: 80 },
            { label: '标的金额', name: 'markSum', index: 'mark_sum', width: 80 },
            { label: '回款方式', name: 'remMethod', index: 'rem_method', width: 80 },
            { label: '预期年化', name: 'markExpect', index: 'mark_expect', width: 80 },
            { label: '发布人', name: 'releaseUser', index: 'release_user', width: 80 },
            { label: '发布时间', name: 'releaseTime', index: 'release_time', width: 80 },
            // { label: '起投金额', name: 'startSum', index: 'start_sum', width: 80 },
			// { label: '最高金额', name: 'maxSum', index: 'max_sum', width: 80 },
			// { label: '开标时间', name: 'startTime', index: 'start_time', width: 80 },
			// { label: '筹标期限', name: 'deadLine', index: 'dead_line', width: 80 },
			{ label: '审核', name: 'markStauts', index: 'mark_stauts', width: 80 }
			// { label: '标的详情', name: 'markContent', index: 'mark_content', width: 80 },
			// { label: '借款人姓名', name: 'name', index: 'name', width: 80 },
			// { label: '性别', name: 'age', index: 'age', width: 80 },
			// { label: '出生日期', name: 'birthday', index: 'birthday', width: 80 },
			// { label: '婚姻状况', name: 'marry', index: 'marry', width: 80 },
			// { label: '职业', name: 'vacation', index: 'vacation', width: 80 },
			// { label: '月收入', name: 'mouthlySum', index: 'mouthly_sum', width: 80 },
			// { label: '学历', name: 'education', index: 'education', width: 80 },
			// { label: '发布人', name: 'releaseUser', index: 'release_user', width: 80 },
			// { label: '发布时间', name: 'releaseTime', index: 'release_time', width: 80 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		tInfMark: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.tInfMark = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.tInfMark.id == null ? "mark/tinfmark/save" : "mark/tinfmark/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.tInfMark),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "mark/tinfmark/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "mark/tinfmark/info/"+id, function(r){
                vm.tInfMark = r.tInfMark;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});